//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_GL_RENDER_STATE_H
#define _UX_GL_RENDER_STATE_H

#include "CStateManager.h"

namespace Engine
{
namespace GLSystems
{

#	pragma pack(push, 1)
	

	//
	// GL Render State
	//

	struct TGLRenderState
	{
		// blending //
		gl_blend_func::type		eSrcRGB,
								eSrcAlpha,
								eDstRGB,
								eDstAlpha;
		gl_blend_equation::type	eModeRGB,
								eModeAlpha;
		e_color_mask::type		eColorMask;
		bool					bBlending;

		// depth //
		gl_compare_mode::type	eDepthFunc;
		bool					bDepthWrite;
		bool					bDepthTest;

		// stencil //
		gl_compare_mode::type	eStencilFunc;
		uint8					uStencilFuncRef;
		uint8					uStencilFuncMask;
		uint8					uStencilMask;
		bool					bStencilTest;

		// culling //
		e_cull_mode::type		eCullMode;

		///
		TGLRenderState():
			eSrcRGB(gl_blend_func::ONE),			eSrcAlpha(gl_blend_func::ONE),
			eDstRGB(gl_blend_func::ZERO),			eDstAlpha(gl_blend_func::ZERO),
			eModeRGB(gl_blend_equation::ADD),		eModeAlpha(gl_blend_equation::ADD),
			eColorMask(e_color_mask::RGBA),			eDepthFunc(gl_compare_mode::LEQUAL),
			bDepthWrite(true),						bDepthTest(true),
			eStencilFunc(gl_compare_mode::EQUAL),	bStencilTest(false),
			uStencilMask(1),						bBlending(false),
			eCullMode(e_cull_mode::DEFAULT),		uStencilFuncRef(0),
			uStencilFuncMask(1)
			{}
			
		void Apply() const;
		void Apply(e_render_state_lock::type eLock) const;
		
		void Invalidate();
		void Validate();

		static CMetaSetIterator * s_GetIterator(const TGLRenderState &sRS);
		static void s_InitMetaData();
	};

#	pragma pack(pop)


	_CREATE_META_OBJECT_FD( TGLRenderState );

//-------------------------------------------------------------------

}	// GLSystems
}	// Engine

#endif	// _UX_GL_RENDER_STATE_H